/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved. 
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.config.service.IConfigCasePhrasesService;
import com.icinfo.cloud.provider.punish.config.dto.PhraseQueryPageDto;
import com.icinfo.cloud.provider.punish.config.dto.PhraseSaveDto;
import com.icinfo.cloud.provider.punish.config.vo.PhraseCategoryVo;
import com.icinfo.cloud.provider.punish.config.vo.PhraseVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 描述: 常用短语表 case_approval_phrases 对应的Controller类.<br>
 *
 * @author 程亚运
 * @date 2022年02月16日
 */
@RestController
@RequestMapping("/phrase")
public class ConfigCasePhrasesController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigCasePhrasesController.class);

    @Autowired
    private IConfigCasePhrasesService caseApprovalPhrasesService;

    /**
     * 查询常用短语列表
     * @param
     * @return
     */
    @PostMapping("/getPhraseList")
    public Result<PageResponse<PhraseVo>> getPhraseList(@Validated @RequestBody PhraseQueryPageDto phraseQueryPageDto){
        PageResponse<PhraseVo> page = caseApprovalPhrasesService.getList(phraseQueryPageDto);
        return Result.success("查询成功!",page);
    }

    /**
     * 查询常用短语详情
     * @param
     * @return
     */
    @PostMapping("/getPhraseList/{id}")
    public Result<PhraseVo> getPhraseDetail(@NotBlank @PathVariable("id") String id){
        return Result.success("查询成功!",caseApprovalPhrasesService.getPhraseDetail(id));
    }

    /**
     * 查询常用短语分类
     * 具体返回字典的值
     * @param
     * @return
     */
    @PostMapping("/getPhraseCategoryList")
    public Result<List<PhraseCategoryVo>> getPhraseCategoryList(){
        // 从字典表取值
        return Result.success("查询成功!",caseApprovalPhrasesService.getPhraseCategoryList());
    }

    /**
     * 新增
     * 新增时id为空
     * @param
     * @return
     */
    @PostMapping("/savePhrase")
    public Result savePhrase(@Validated @RequestBody PhraseSaveDto casePhrases){
        if (caseApprovalPhrasesService.savePhrase(casePhrases)){
            return Result.success("success");
        }
        return Result.error("fail！");
    }

    /**
     * 修改
     *
     * @param
     * @return
     */
    @PostMapping("/modifyPhrase")
    public Result modifyPhrase(@Validated @RequestBody PhraseSaveDto casePhrases){
        if (caseApprovalPhrasesService.modifyPhrase(casePhrases)){
            return Result.success("success");
        }
        return Result.error("fail！");
    }

    /**
     * 删除短语
     * 短语id
     * @param id
     * @return
     */
    @PostMapping("/removePhrase/{id}")
    public Result removePhrase(@NotBlank @PathVariable("id") String id){
        //先做物理删除，后面在做逻辑删除
        if (caseApprovalPhrasesService.removePhrase(id)){
            return Result.success("success");
        }
        return Result.error("fail！");
    }
}